package com.tianheng.wanzhou.datacollecting.netty.kongyajiR150.receiver.receiverImpl;

import com.baomidou.mybatisplus.extension.service.IService;
import com.tianheng.wanzhou.datacollecting.db.entity.AirCompressorR1501;
import com.tianheng.wanzhou.datacollecting.db.service.IAirCompressorR1501Service;
import com.tianheng.wanzhou.datacollecting.netty.kongyajiR150.receiver.Receiver;
import com.tianheng.wanzhou.datacollecting.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: yujw
 * @Date: 2020/5/19 13:10
 * @Version 1.0
 */
@Component("r150A1")
public class Air1Receiver extends Receiver {

    @Autowired
    IAirCompressorR1501Service service;

    @Override
    public Object parseMessage(String message, String ip, Integer company, Integer workshop, String machineId) {
        AirCompressorR1501 airCompressorR1501 = new AirCompressorR1501();
        if(message.substring(4,6).equals("10")){
            String str = message.substring(3 * 2).substring(0, 4);
            String binary = StrUtil.hexStr2BinaryStr(str);
            char[] x = binary.toCharArray();
//            AirCompressorR1501 airCompressorR1501 = new AirCompressorR1501();
            airCompressorR1501.setMachineIp(ip);
            airCompressorR1501.setCompany(company);
            airCompressorR1501.setWorkshop(workshop);
            airCompressorR1501.setMachineId(machineId);
            airCompressorR1501.setMainDriveMotorTripStop(Character.digit(x[0], 2));
            airCompressorR1501.setAuxOilPumpOutput(Character.digit(x[1], 2));
            airCompressorR1501.setCoolingWaterSolenoid(Character.digit(x[2], 2));
            airCompressorR1501.setRemoteAlarmOutput(Character.digit(x[3], 2));
            airCompressorR1501.setRemoteTripOutput(Character.digit(x[4], 2));
            airCompressorR1501.setHorn(Character.digit(x[5], 2));
            airCompressorR1501.setPanelTripIndication(Character.digit(x[6], 2));
            airCompressorR1501.setPanelAlarmIndication(Character.digit(x[7], 2));
        }

        return airCompressorR1501;
    }

    @Override
    public IService getService() {
        return service;
    }

}
